package org.stwy.comm.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.stwy.pro.property.PropertyEntity;

import com.rap.common.exception.ServiceException;
import com.rap.common.service.BaseTreeServiceImpl;
import com.rap.common.service.IService;
import com.rap.frame.md.object.ObjectEntity;
import com.rap.frame.md.object.ObjectService;
import com.rap.frame.md.objectattr.ObjectAttrEntity;
import com.rap.frame.md.objectattr.ObjectAttrService;
import com.rap.frame.web.ActionResultModel;
import com.rap.frame.web.BaseController;
import com.rap.frame.web.QueryRequest;

public class BaseRecordsController<T extends BaseRecordsEntity> extends BaseController<T> {
	
	@Autowired
	private ObjectService objectService;
	@Autowired
	private ObjectAttrService objectAttrService;
	
	private BaseRecordsServiceImpl getService(){
		return (BaseRecordsServiceImpl)super.baseService;
	}
	/**
	 * 修改
	 * 
	 * @param entity
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "/update")
	@ResponseBody
	public ActionResultModel update(ServletRequest request, Model model,
			T entity) {
		ActionResultModel arm = new ActionResultModel();
		try {
			T newEntity = (T) getService().update(entity);
			arm.setRecords(newEntity);
			arm.setSuccess(true);
		} catch (ServiceException e) {
			arm.setSuccess(false);
			arm.setMsg(e.getMessage());
		}
		return arm;
	}
	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "/reuse")
	@ResponseBody
	public ActionResultModel reuse(ServletRequest request, Model model,
			String[] pks) {
		ActionResultModel arm = new ActionResultModel();
		try {
			getService().reuse(pks);
			arm.setSuccess(true);
		} catch (ServiceException e) {
			arm.setSuccess(false);
			arm.setMsg(e.getMessage());
		}
		return arm;
	}
}
